import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    redirect: '/addwork',
    children:[
      {
        path: '/addwork',
        name: 'addwork',
        component: () => import('../views/reportwork/addwork'),
      },
      {
        path: '/makework',
        name: 'makework',
        component: () => import('../views/reportwork/makework'),
      },
      {
        path: '/worksetting',
        name: 'worksetting',
        component: () => import('../views/reportwork/worksetting'),
      },
      {
        path: '/message',
        name: 'message',
        component: () => import('../views/message'),
      },
      {
        path: '/creategroup',
        name: 'creategroup',
        component: () => import('../views/group/creategroup'),
      },
      {
        path: '/task',
        name: 'task',
        component: () => import('../views/task'),
      },
      {
        path: '/staproject',
        name: 'staproject',
        component: () => import('../views/statistics/staproject'),
      },
      {
        path: '/statask',
        name: 'statask',
        component: () => import('../views/statistics/statask'),
      },
      {
        path: '/stataskman',
        name: 'stataskman',
        component: () => import('../views/statistics/stataskman'),
      },
      {
        path: '/stapassman',
        name: 'stapassman',
        component: () => import('../views/statistics/stapassman'),
      },
      {
        path: '/stagrouptype',
        name: 'stagrouptype',
        component: () => import('../views/statistics/stagrouptype'),
      },
      {
        path: '/workkind',
        name: 'workkind',
        component: () => import('../views/systemconfig/workkind'),
      },
      {
        path: '/grouptype',
        name: 'grouptype',
        component: () => import('../views/systemconfig/grouptype'),
      },
      {
        path: '/project',
        name: 'project',
        component: () => import('../views/systemconfig/project'),
      },
    ],
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/Login.vue'),
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('../views/Register.vue'),
  }
]
const router = new VueRouter({
  base: process.env.BASE_URL,
  routes
})
router.beforeEach(function (to, from, next) {
  if (to.name == 'login'|| to.name == 'register') {
    next();
  } else {
    if (sessionStorage.getItem("loginFlag")=='SUCCESS') {
      next()
    } else {
      next({ name: 'login' })
    }
  }
})


export default router
